// app/api/table-presets/[id]/route.ts import { NextRequest, NextResponse } from "next/server" import { getServerSession } from "next-auth" import { authOptions } from "@/app/api/auth/[...nextauth]/route" import db from "@/db/db" import { tablePresets } from "@/db/schema/setting" import { eq } from "drizzle-orm" export async function PUT( request: NextRequest, { params }: { params: { id: string } } ) { try { const session = await getServerSession(authOptions) if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) } const presetId = params.id const body = await request.json() const updatedPreset = await db .update(tablePresets) .set({ ...body, updatedAt: new Date(), }) .where(eq(tablePresets.id, presetId)) .returning() return NextResponse.json(updatedPreset[0]) } catch (error) { console.error("Error updating preset:", error) return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }) } } export async function DELETE( request: NextRequest, { params }: { params: { id: string } } ) { try { const session = await getServerSession(authOptions) if (!session?.user?.id) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }) } const presetId = params.id await db.delete(tablePresets).where(eq(tablePresets.id, presetId)) return NextResponse.json({ success: true }) } catch (error) { console.error("Error deleting preset:", error) return NextResponse.json({ error: "Internal Server Error" }, { status: 500 }) } }